﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PerformanceTest
{
    public class GenericCollection
    {
        public static void TestMain(string[] args)
        {
            ValueTypePerfTest();
            ReferenceTypePerfTest();
            Console.ReadLine();
        }
        public static void ValueTypePerfTest()
        {
            const Int32 count = 10000000;
            using (new OperationTimer("List<Int32>"))
            {
                List<Int32> l = new List<Int32>(count);
                for (Int32 i = 0; i < count; i++)
                {
                    l.Add(i);
                    Int32 x = l[i];
                }
                l = null;
            }
            using (new OperationTimer("ArrayList of Int32"))
            {
                ArrayList a = new ArrayList();
                for (Int32 i = 0; i < count; i++)
                {
                    a.Add(i);
                    Int32 x = (Int32)a[i];
                }
                a = null;
            }

        }

        public static void ReferenceTypePerfTest()
        {
            const Int32 count = 10000000;
            using (new OperationTimer("List<string>"))
            {
                List<string> l = new List<string>();
                for (Int32 i = 0; i < count; i++)
                {
                    l.Add("X");
                    string x = l[i];
                }
                l = null;
            }
            using (new OperationTimer("ArrayList of string"))
            {
                ArrayList a = new ArrayList();
                for (Int32 i = 0; i < count; i++)
                {
                    a.Add("X");
                    string x = (String)a[i];
                }
                a = null;
            }
            Console.ReadLine();
        }
    }

}
